﻿CREATE PROCEDURE [dbo].[proc_Finance_RunningAccount_OrderId]
	(
		@OrderId nvarchar(50)
	)
AS
	Select
		R.Id,
		R.CreateDate,
		R.TradeDate,
		R.Summary,
		isnull((Select Title From Finance_AccountsType Where Id=R.AccountsTypeId),'...') as AccountsType,
		isnull((Select Title From Finance_Subject Where Id=R.SubjectId),'...') As Subject,
		isnull((Select Title From Finance_PaymentType Where Id=R.PaymentTypeId),'...') As PaymentType,
		isnull((Select OpenBank From Finance_Bank Where Id=R.BankId),'...') As Bank,
		Income,
		Outlay,
		isnull((Select EName From Employee Where UserName=R.Agent),'...') As AgentName,
		isnull((Select EName From Employee Where UserName=R.UserName),'...') As EName,
		BillNumber,
		Description
	From Finance_RunningAccount R 
	Where R.OrderId=@OrderId Order by R.CreateDate ASC
	RETURN
